using MusicStore.Dashboard.Client.SalesServiceReference;

namespace MusicStore.Dashboard.Client.Commands
{
  public class LoadSalesByGenreCommand : LoadSalesCommandBase<SalesByGenre>
  {
    protected override void Execute(SalesClient client)
    {
      Sales.Clear();

      client.GetSalesByGenreCompleted += ClientOnGetSalesByGenreCompleted;
      client.GetSalesByGenreAsync(this);
    }

    private void ClientOnGetSalesByGenreCompleted(object sender, GetSalesByGenreCompletedEventArgs args)
    {
      var wLoadSalesCommand = (SalesClient)sender;
      wLoadSalesCommand.GetSalesByGenreCompleted -= ClientOnGetSalesByGenreCompleted;

      var wSalesCommand = (LoadSalesByGenreCommand)args.UserState;
      wSalesCommand.Sales = args.Result;

      SetComplete();
    }
  }
}